﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace yule.Data.SQL2008
{
    /// <summary>
    /// SQL2008数据库访问类
    /// </summary>
    public sealed class DBHelper : yule.Data.DBHelper
    {

        public DBHelper(string connectionString)
        {
            this.ConnectionString = connectionString;
        }

        public override yule.Data.Transaction CreateTransaction()
        {
            System.Data.Common.DbConnection conn = this.CreateDbConnection(this.ConnectionString);
            //打开连接
            conn.Open();

            System.Data.Common.DbTransaction tran = conn.BeginTransaction();
            return new yule.Data.SQL2008.Transaction(tran);
        }


        protected override System.Data.Common.DbCommand CreateDbCommand()
        {
            return new System.Data.SqlClient.SqlCommand();
        }


        protected override System.Data.Common.DbConnection CreateDbConnection(string connectionString)
        {
            return new System.Data.SqlClient.SqlConnection(connectionString);
        }

        protected override System.Data.Common.DbDataAdapter CreateDbDataAdapter(System.Data.Common.DbCommand cmd)
        {
            System.Data.SqlClient.SqlCommand sqlcmd = cmd as System.Data.SqlClient.SqlCommand;
            return new System.Data.SqlClient.SqlDataAdapter(sqlcmd);
        }

        public override System.Data.Common.DbParameter CreateDbParameter(string parameterName, object value, DbType dbType, ParameterDirection direction = ParameterDirection.Input)
        {
            System.Data.SqlClient.SqlParameter parameter = new SqlParameter();

            parameter.ParameterName = parameterName;
            parameter.Value = value;
            parameter.DbType = dbType;
            parameter.Direction = direction;

            return parameter;
        }

    }
}
